package com.action.mvc.sm.rabbit;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

/**
 * 注册 MQ
 */
@Component
public class MessageExecuteConfig {

    public final static String MESSAGE_QUEUE = "message.execute.queue";
    public final static String MESSAGE_EXCHANGE = "message.execute.exchange";
    public final static String MESSAGE_ROUTER_KEY = "message.execute.routerKey";

    @Bean
    DirectExchange messageExecuteExchange() {
        return new DirectExchange(MESSAGE_EXCHANGE);
    }

    @Bean
    public Queue queueForMessageExecute() {
        return new Queue(MESSAGE_QUEUE);
    }

    @Bean
    Binding bindingMessageExecuteExchangeMessages(Queue queueForMessageExecute, DirectExchange messageExecuteExchange) {
        return BindingBuilder.bind(queueForMessageExecute).to(messageExecuteExchange).with(MESSAGE_ROUTER_KEY);
    }

}

